const state = {
  activeFormData: Object.create(null),
  chooseFieldId: '',
  groupId: ''
};

const mutations = {
  ADDFORM(state, data) {
    // console.log('data为', data);
    state.chooseFieldId = data.filedId;
    state.activeFormData = data
  },
  // 设置属性值
  SETPROP(state, data) {
    const {key, value} = data;
    state.activeFormData[key] = value;
  },

  // 设置tag
  SETTAG(state, data) {
    const {key, value} = data;
    state.activeFormData['tag'] = value;
  },

  ADDGROUPID(state, data) {
    state.groupId = data;
  },

  // 添加校验,包含正则(regular)和函数(fn)
  ADDVERFIGY(state, type) {
    if (Object.keys(state.activeFormData).length !== 0) {
      // 正则
      if (type === 'regular') {
        state.activeFormData.regList.push({
          reg: '',
          msg: ''
        })
      } else {
        state.activeFormData.fnList.push('')
      }
    }
  },

  // 删除正则校验
  DELREGULAR(state, index) {
    state.activeFormData.regList.splice(index, 1)
  },

  // 删除函数校验
  DELFN(state, index) {
    state.activeFormData.fnList.splice(index, 1)
  },

  // 添加下拉选项
  ADDOPTION(state) {
    state.activeFormData.options.push({
      label: '',
      value: ''
    })
  },

  // 删除下拉选项
  DELOPTION(state, index) {
    state.activeFormData.options.splice(index, 1);
  },

};

const actions = {

};

const getters = {

};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
